Skip to content

Conversation

@MichaelChirico
Copy link
Member

Searched the sources:

grep -Er "const\b.*[*]\w+\s*=\s*[A-Z]+([^OR]|[^A]R)[(]" src

This is some low-hanging fruit in terms of better use of read-only accessors. There will be other cases where we can make the change to a const pointer as well, but those can't be identified with a simple regex.

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (e13ea60) to head (9b034c8).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7611      +/-   ##
==========================================
- Coverage   99.02%   99.02%   -0.01%     
==========================================
  Files          87       87              
  Lines       16903    16890      -13     
==========================================
- Hits        16739    16726      -13     
  Misses        164      164              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jan 20, 2026

No obvious timing issues in HEAD=ro-access
Comparison Plot

Generated via commit 9b034c8

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 3 minutes and 0 seconds
Installing different package versions 43 seconds
Running and plotting the test cases 4 minutes and 26 seconds

@MichaelChirico
Copy link
Member Author

Another big class of cases where we could switch to _RO are call sites like INTEGER(x)[k] -- once we do [ to the output, we know we're only reading from x.

There are roughly 240 such sites (grep -Er "(INTEGER|LOGICAL|REAL|COMPLEX|RAW)[(]\w+[)]\[[^=]*$"), I just suspect it's not worth it to change them.

@MichaelChirico
Copy link
Member Author

I see this has some (or total) overlap with #7394. I think it's good to break out the changes into minimally-digestible parts -- here we focus only on const <type> *<var> = <writeable>(x) --> const <type> *<var> = <read-only>(x).

@ben-schwen
Copy link
Member

Should we add an accessor for integer64?

#define INTEGER64_RO(x)	((const int64_t *) DATAPTR_RO(x))

@MichaelChirico
Copy link
Member Author

Should we add an accessor for integer64?

#define INTEGER64_RO(x)	((const int64_t *) DATAPTR_RO(x))

Good point, though I think out of scope -- #7618

Co-authored-by: Benjamin Schwendinger <[email protected]>
const R_xlen_t n = xlength(x);
if (n==0)
return ScalarInteger(0); // empty vector
int first = LOGICAL(x)[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR is about smth else but just spotted this :/

should be bool. same applies for second and third

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's right -- see below first==NA_INTEGER, that's not possible with bool.

Maybe I'm missing something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! But then still should be NA_LOGICAL. Also only cosmetics since R defines like this

#define NA_LOGICAL	R_NaInt
#define NA_INTEGER	R_NaInt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgive me, I still don't quite follow... int is the correct type for LOGICAL(), if we implicitly cast it to bool, then if first is TRUE or NA, first == NA_INTEGER will either pass (by (bool)NA_INTEGER) or fail (by (int)(bool)first turning NA into 1).

Copy link
Member

@aitap aitap Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be Rboolean. Those are guaranteed to fit all of TRUE, FALSE, NA_LOGICAL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot the outcome of that episode, you're right. int is appropriate, bool and Rboolean aren't supposed to handle NA_LOGICAL.

@aitap
Copy link
Member

aitap commented Jan 22, 2026 via email

MichaelChirico and others added 4 commits January 23, 2026 11:27
Co-authored-by: Benjamin Schwendinger <[email protected]>
Keep the casts because they are currently necessary for the integer64 case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants